package com.jdwx.opengl.face.utils;

/**
 * @author bai
 * @date 2020/6/19
 * @description
 */

import com.google.gson.Gson;

/**
 * ****************************
 * SPD_PDA_Module
 *
 * @AUTHER： YBB
 * CreateTime： 2019/7/30 10:07
 * Describe：
 * ****************************
 */
public class JSONUtil {
    private static Gson gson = null;

    static {
        if (gson == null) {
            gson = new Gson();
        }
    }

    private JSONUtil() {
    }

    /**
     * 将object对象转成json字符串
     *
     * @param object
     * @return
     */
    public static String Serializable(Object object) {
        String gsonString = null;
        if (gson != null) {
            gsonString = gson.toJson(object);
        }
        return gsonString;
    }

    /**
     * 将gsonString转成泛型bean
     *
     * @param str
     * @param type
     * @return
     */
    public static <T> T DeserializeObject(String str, Class<T> type) {
        T t = null;
        if (gson != null) {
            t = gson.fromJson(str, type);
        }
        return t;
    }
}